﻿#region Header
// ------------------------ Licence / Copyright ------------------------
// 
// ScrumTable for Scrum Meeting Support
// Copyright © HSR - Hochschule für Technik Rapperswil
// All Rights Reserved
// 
// Author:
//  Michael Gfeller Silvan Gehrig Patrick Boos
// 
// ---------------------------------------------------------------------
#endregion

#region Usings

using System;
using System.Collections.Generic;
using System.Windows;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using ScrumTable.UI.View.Converter;
#endregion

namespace ScrumTable.UI.ViewModel.Test
{
    /// <summary>
    /// Test the ConverterEnumEqual
    /// </summary>
    [TestClass]
    public class ConverterAllowedValuesToElementMenuItemsTest
    {
        #region Additional test attributes

        public ConverterAllowedValuesToElementMenuItems Converter { get; set; }
        public ConverterAllowedValuesToElementMenuItemsBack ConverterBack { get; set; }
        
        #endregion

             #region Constructors / Destructor
        //--------------------------------------------------------------------
        // Constructors / Destructor
        //--------------------------------------------------------------------

        public ConverterAllowedValuesToElementMenuItemsTest()
        {
            Converter = new ConverterAllowedValuesToElementMenuItems();
            ConverterBack = new ConverterAllowedValuesToElementMenuItemsBack();

        }
        #endregion



        #region Methods
        //--------------------------------------------------------------------
        // Methods
        //--------------------------------------------------------------------


        [TestMethod]
        public void TestMapping()
        {
            List<object> tmpList = new List<object>() { 0, 1, 2, 3, 4, 5, 6, 7 };
            var convertedList = Converter.Convert(tmpList, null, null, null) as List<object>;
            Assert.IsNotNull(convertedList);
            Assert.AreEqual(tmpList[0].ToString(), convertedList[1].ToString());
            Assert.AreEqual(tmpList[1].ToString(), convertedList[0].ToString());
            Assert.AreEqual(tmpList[2].ToString(), convertedList[2].ToString());
            Assert.AreEqual(tmpList[3].ToString(), convertedList[3].ToString());
            Assert.AreEqual(tmpList[4].ToString(), convertedList[4].ToString());
            Assert.AreEqual(tmpList[5].ToString(), convertedList[5].ToString());
            Assert.AreEqual(tmpList[6].ToString(), convertedList[7].ToString());
            Assert.AreEqual(tmpList[7].ToString(), convertedList[6].ToString());
        }


        [TestMethod]
        public void TestElevenElements()
        { 
            List<object> tmpList = new List<object>() {0,1,2,3,4,5,6,7,8,9,10};
            var convertedList = Converter.Convert(tmpList, null, null, null) as List<object>;
            Assert.IsNotNull(convertedList);
            Assert.IsTrue(convertedList[1] is ElementMenuHierarchical);
            Assert.AreEqual(4,((ElementMenuHierarchical)convertedList[1]).Element.Count);
        }


        [TestMethod]
        public void TestNameOfCombinedElement()
        {
            List<object> tmpList = new List<object>() {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
            var convertedList = Converter.Convert(tmpList, null, null, null) as List<object>;
            Assert.IsNotNull(convertedList);
            Assert.IsTrue(convertedList[1] is ElementMenuHierarchical);
            Assert.AreEqual("0" + Environment.NewLine + "-" + Environment.NewLine + "3", convertedList[1].ToString());
        }

        [TestMethod]
        public void TestTwentyElements()
        {
            List<object> tmpList = new List<object>() { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,12,13,14,15,16,17,18,19, 20,21,22};
            var convertedList = Converter.Convert(tmpList, null, null, null) as List<object>;
            Assert.IsNotNull(convertedList);
            Assert.IsTrue(convertedList[1] is ElementMenuHierarchical);
            Assert.IsTrue(convertedList[0] is ElementMenuHierarchical);
            Assert.AreEqual(8, ((ElementMenuHierarchical)convertedList[1]).Element.Count);
            Assert.AreEqual(8, ((ElementMenuHierarchical)convertedList[0]).Element.Count);
            Assert.AreEqual(2, ((ElementMenuHierarchical)convertedList[2]).Element.Count);
        }

        [TestMethod]
        public void TextMaxElements()
        {
            List<object> tmpList = new List<object>();
            for (int i = 0; i < 100; i++)
            {
                tmpList.Add(i);
            }
            var convertedList = Converter.Convert(tmpList, null, null, null) as List<object>;
            Assert.IsNotNull(convertedList);
            Assert.AreEqual(8, ((ElementMenuHierarchical)convertedList[0]).Element.Count);
            Assert.AreEqual(8, ((ElementMenuHierarchical)convertedList[1]).Element.Count);
            Assert.AreEqual(8, ((ElementMenuHierarchical)convertedList[2]).Element.Count);
            Assert.AreEqual(8, ((ElementMenuHierarchical)convertedList[3]).Element.Count);
            Assert.AreEqual(8, ((ElementMenuHierarchical)convertedList[4]).Element.Count);
            Assert.AreEqual(8, ((ElementMenuHierarchical)convertedList[5]).Element.Count);
            Assert.AreEqual(8, ((ElementMenuHierarchical)convertedList[6]).Element.Count);
            Assert.AreEqual(8, ((ElementMenuHierarchical)convertedList[7]).Element.Count);
        }



        [TestMethod]
        public void TestTwentyElementsBack()
        {
            List<object> tmpList = new List<object>() { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22 };
            var convertedList = ConverterBack.Convert(tmpList, null, null, null) as List<object>;
            Assert.IsNotNull(convertedList);
            Assert.IsTrue(convertedList[1] is ElementMenuHierarchical);
            Assert.IsTrue(convertedList[0] is ElementMenuHierarchical);
            Assert.AreEqual(8, ((ElementMenuHierarchical)convertedList[7]).Element.Count);
            Assert.AreEqual(8, ((ElementMenuHierarchical)convertedList[6]).Element.Count);
            Assert.AreEqual(2, ((ElementMenuHierarchical)convertedList[5]).Element.Count);
        }



        [TestMethod]
        public void TestNameOfCombinedElementBack()
        {
            List<object> tmpList = new List<object>() { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
            var convertedList = ConverterBack.Convert(tmpList, null, null, null) as List<object>;
            Assert.IsNotNull(convertedList);
            Assert.IsTrue(convertedList[6] is ElementMenuHierarchical);
            Assert.AreEqual(7, ((ElementMenuHierarchical)convertedList[6]).Element[1]);
            Assert.AreEqual(8, ((ElementMenuHierarchical)convertedList[6]).Element[0]);
            Assert.AreEqual(9, ((ElementMenuHierarchical)convertedList[6]).Element[2]);
            Assert.AreEqual("7" + Environment.NewLine + "-" + Environment.NewLine + "10", convertedList[6].ToString());
        }



        [TestMethod]
        public void TestMappingBack()
        {
            List<object> tmpList = new List<object>() { 0, 1, 2, 3, 4, 5, 6, 7 };
            var convertedList = ConverterBack.Convert(tmpList, null, null, null) as List<object>;
            Assert.IsNotNull(convertedList);
            Assert.AreEqual(tmpList[0].ToString(), convertedList[1].ToString());
            Assert.AreEqual(tmpList[1].ToString(), convertedList[0].ToString());
            Assert.AreEqual(tmpList[2].ToString(), convertedList[2].ToString());
            Assert.AreEqual(tmpList[3].ToString(), convertedList[3].ToString());
            Assert.AreEqual(tmpList[4].ToString(), convertedList[4].ToString());
            Assert.AreEqual(tmpList[5].ToString(), convertedList[5].ToString());
            Assert.AreEqual(tmpList[6].ToString(), convertedList[7].ToString());
            Assert.AreEqual(tmpList[7].ToString(), convertedList[6].ToString());
        }



        [TestMethod]
        public void TestMapping5ItemsBack()
        {
            List<object> tmpList = new List<object>() { 0, 1, 2, 3, 4 };
            var convertedList = ConverterBack.Convert(tmpList, null, null, null) as List<object>;
            Assert.IsNotNull(convertedList);
            Assert.AreEqual(tmpList[0].ToString(), convertedList[1].ToString());
            Assert.AreEqual(tmpList[1].ToString(), convertedList[0].ToString());
            Assert.AreEqual(tmpList[2].ToString(), convertedList[2].ToString());
            Assert.AreEqual(tmpList[3].ToString(), convertedList[3].ToString());
            Assert.AreEqual(tmpList[4].ToString(), convertedList[4].ToString());
    
    
        }



        #endregion
    }
}
